<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>小米: <span>1999.99</span>元 <button>-</button> <b>0</b><button>+</button>小计: <strong>0</strong>元</div>
    <div>小米: <span>11</span>元 <button>-</button> <b>0</b><button>+</button>小计: <strong>0</strong>元</div>
    <div>小米: <span>1</span>元 <button>-</button> <b>0</b><button>+</button>小计: <strong>0</strong>元</div>
    <script>
        var odiv = document.getElementsByTagName('div')
        for(var i=0;i<odiv.length;i++) {
           fn(odiv[i])
        }
        function fn(odiv) {
            var spans = odiv.getElementsByTagName('span')
            var btn = odiv.getElementsByTagName('button')
            var bs = odiv.getElementsByTagName('b')
            var strongs = odiv.getElementsByTagName('strong')

            // 点击减号事件
            btn[0].onclick = function(){
                if(bs[0].innerHTML <= 0) {
                    return
                }else {
                    bs[0].innerHTML--
                }
                strongs[0].innerHTML = spans[0].innerHTML * bs[0].innerHTML
            }
            // 点击加号事件
            btn[1].onclick = function(){
                bs[0].innerHTML++
                strongs[0].innerHTML = spans[0].innerHTML * bs[0].innerHTML
            }
        }
</script>
</body>
</html>